package com.geqian.web.file;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationObserver;

import java.io.File;

public class FileListener extends FileAlterationListenerAdaptor {

	@Override
	public void onStart(FileAlterationObserver observer) {
		super.onStart(observer);
	}

	@Override
	public void onDirectoryCreate(File directory) {
		System.out.println("新建目录：" + directory.getAbsolutePath());
	}

	@Override
	public void onDirectoryChange(File directory) {
		System.out.println("发生更改目录：" + directory.getAbsolutePath());
	}

	@Override
	public void onDirectoryDelete(File directory) {
		System.out.println("删除目录：" + directory.getAbsolutePath());
	}

	@Override
	public void onFileCreate(File file) {
		String compressedPath = file.getAbsolutePath();
		System.out.println("新建文件：" + compressedPath);
		if (file.canRead()) {
			// TODO 读取或重新加载文件内容
			System.out.println("读取或重新加载文件内容中...");
		}
	}

	@Override
	public void onFileChange(File file) {
		String compressedPath = file.getAbsolutePath();
		System.out.println("修改文件：" + compressedPath);
	}

	@Override
	public void onFileDelete(File file) {
		System.out.println("删除文件：" + file.getAbsolutePath());
	}

	@Override
	public void onStop(FileAlterationObserver observer) {
		super.onStop(observer);
	}
}
